﻿<StackPanel 
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"  
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  
    x:Class="Komunikator.Views.SearchPeopleForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Komunikator.Controls"
    xmlns:domain="clr-namespace:Komunikator.Web"
    xmlns:Views="clr-namespace:Komunikator.Views"
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"  
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:my="clr-namespace:System;assembly=mscorlib">
    <Grid x:Name="LayoutRoot" Background="White">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <riaControls:DomainDataSource x:Name="CountriesSource" QueryName="GetCountries">
            <riaControls:DomainDataSource.DomainContext>
                <domain:CommunicatorDomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>

        <riaControls:DomainDataSource x:Name="CitiesSource" QueryName="GetCitiesInCountry">
            <riaControls:DomainDataSource.DomainContext>
                <domain:CommunicatorDomainContext />
            </riaControls:DomainDataSource.DomainContext>
            <riaControls:DomainDataSource.QueryParameters>
                <riaControls:Parameter ParameterName="country" Value="{Binding ElementName=autoCompleteBoxCountry, Path=Text}" />
            </riaControls:DomainDataSource.QueryParameters>
        </riaControls:DomainDataSource>

        <riaControls:DomainDataSource x:Name="SearchResultsSource" QueryName="SearchPeople" AutoLoad="False">
            <riaControls:DomainDataSource.DomainContext>
                <domain:CommunicatorDomainContext />
            </riaControls:DomainDataSource.DomainContext>
            <riaControls:DomainDataSource.QueryParameters>
                <riaControls:Parameter ParameterName="firstName" Value="{Binding FirstName}" />
                <riaControls:Parameter ParameterName="lastName" Value="{Binding LastName}" />
                <riaControls:Parameter ParameterName="sex" Value="{Binding Sex}" />
                <riaControls:Parameter ParameterName="ageFrom" Value="{Binding AgeFrom}" />
                <riaControls:Parameter ParameterName="ageTo" Value="{Binding AgeTo}" />
                <riaControls:Parameter ParameterName="country" Value="{Binding Country}" />
                <riaControls:Parameter ParameterName="city" Value="{Binding City}" />
                <riaControls:Parameter ParameterName="street" Value="{Binding Street}" />
            </riaControls:DomainDataSource.QueryParameters>
        </riaControls:DomainDataSource>
                
        
        <Grid HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            
            <TextBlock FontSize="14" Text="Szukaj znajomych" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="3"/>
            <local:BusyIndicator x:Name="busyIndicator" Grid.Row="1" Margin="5">
                <Grid Width="Auto">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>

                <sdk:Label Target="{Binding ElementName=tbFirstName}" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" />
                <TextBox Text="{Binding FirstName, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" x:Name="tbFirstName" Grid.Column="1" Grid.Row="0"  HorizontalAlignment="Left" Margin="3" Width="175" />

                <sdk:Label Target="{Binding ElementName=tbLastName}" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" />
                <TextBox Text="{Binding LastName, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" x:Name="tbLastName" Grid.Column="1" Grid.Row="1"  HorizontalAlignment="Left" Width="175" Margin="3" />

                <sdk:Label Target="{Binding ElementName=comboBoxSex}" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" />
                <ComboBox HorizontalAlignment="Left" x:Name="comboBoxSex" Grid.Column="1" Grid.Row="2" Width="120" Margin="3" SelectedValuePath="Content" SelectedValue="{Binding Sex, Mode=TwoWay}" Height="23">
                    <ComboBoxItem Content="" />
                    <ComboBoxItem Content="Mężczyzna" />
                    <ComboBoxItem Content="Kobieta" />
                </ComboBox>
                <Grid Grid.ColumnSpan="2" Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <sdk:Label Target="{Binding ElementName=tbAgeFrom}" Grid.Column="0" HorizontalAlignment="Right" />
                    <TextBox Text="{Binding AgeFrom, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True, Converter={StaticResource NullableValueConverter}}" x:Name="tbAgeFrom" Grid.Column="1"  HorizontalAlignment="Left" Width="40" Margin="3" />
                    <sdk:Label Target="{Binding ElementName=tbAgeTo}" Grid.Column="2" HorizontalAlignment="Right" />
                    <TextBox Text="{Binding AgeTo, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True, Converter={StaticResource NullableValueConverter}}" x:Name="tbAgeTo" Grid.Column="3" HorizontalAlignment="Left" Width="40" Margin="3" />
                </Grid>

                <sdk:Label Target="{Binding ElementName=autoCompleteBoxCountry}" Grid.Column="0" Grid.Row="4" HorizontalAlignment="Right" />
                <sdk:AutoCompleteBox Text="{Binding Country, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" x:Name="autoCompleteBoxCountry" Grid.Column="1" Grid.Row="4"  HorizontalAlignment="Left" Width="175" Margin="3" ItemsSource="{Binding Path=Data, ElementName=CountriesSource}" ValueMemberPath="CountryName">
                    <sdk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CountryName}" />
                        </DataTemplate>
                    </sdk:AutoCompleteBox.ItemTemplate>
                </sdk:AutoCompleteBox>

                <sdk:Label Target="{Binding ElementName=autoCompleteBoxCity}" Grid.Column="0" Grid.Row="5" HorizontalAlignment="Right" />
                <sdk:AutoCompleteBox Text="{Binding City, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" x:Name="autoCompleteBoxCity" Grid.Column="1" Grid.Row="5"  HorizontalAlignment="Left" Width="175" Margin="3" ItemsSource="{Binding Path=Data, ElementName=CitiesSource}" ValueMemberPath="CityName">
                    <sdk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CityName}" />
                        </DataTemplate>
                    </sdk:AutoCompleteBox.ItemTemplate>
                </sdk:AutoCompleteBox>

                <sdk:Label Target="{Binding ElementName=tbStreet}" Grid.Column="0" Grid.Row="6" HorizontalAlignment="Right" />
                <TextBox Text="{Binding Street, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" x:Name="tbStreet" Grid.Column="1" Grid.Row="6"  HorizontalAlignment="Left" Width="175" Margin="3" />
                <Button x:Name="buttonSearchPeople" Content="Szukaj" Click="buttonSearchPeople_Click" Width="100" Grid.Row="7" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="3" />
            </Grid>
            </local:BusyIndicator>

            <sdk:DataGrid HorizontalAlignment="Center" 
                      ItemsSource="{Binding Data, ElementName=SearchResultsSource}" AutoGenerateColumns="False" DataContext="{Binding}" Grid.Row="1" Grid.Column="1" Width="650" Margin="5" AllowDrop="False" IsReadOnly="True">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Header="Login" Binding="{Binding Path=aspnet_Users.UserName}" />
                    <sdk:DataGridTextColumn Header="Imię" Binding="{Binding FirstName}" />
                    <sdk:DataGridTextColumn Header="Nazwisko" Binding="{Binding LastName}" />
                    <sdk:DataGridTextColumn Header="Płeć" Binding="{Binding Sex, Converter={StaticResource sexConverter}}" />
                    <sdk:DataGridTextColumn Header="Wiek" Binding="{Binding Age}" />
                    <sdk:DataGridTextColumn Header="Kraj" Binding="{Binding Path=Countries.CountryName}" />
                    <sdk:DataGridTextColumn Header="Miasto" Binding="{Binding Path=Cities.CityName}" />
                    <sdk:DataGridTextColumn Header="Ulica" Binding="{Binding Street}" />
                    <sdk:DataGridTemplateColumn Width="80">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button x:Name="Add" Content="Dodaj" Click="Button_Click"/>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
        </Grid>
           
    </Grid>
</StackPanel>
